package org.jeecg.modules.demo.hd.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.demo.hd.entity.AppSpace;
import org.jeecg.modules.demo.hd.mapper.AppSpaceMapper;
import org.jeecg.modules.demo.hd.service.IAppSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: app_space
 * @Author: jeecg-boot
 * @Date:   2025-04-16
 * @Version: V1.0
 */
@Service
public class AppSpaceServiceImpl extends ServiceImpl<AppSpaceMapper, AppSpace> implements IAppSpaceService {

    //封装了redis操作各种方法
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<AppSpace> getList() {

        Object o = redisUtil.get(key());
        if(ObjectUtils.isNotNull(o))
        {
            List<AppSpace> list =(List<AppSpace> )o;
            return list;
        }
        else {
            List<AppSpace> list = this.list();
            redisUtil.set(key(),list);
            return list;
        }
    }

    @Override
    public void cleanRedis() {
        redisUtil.del(key());
    }


    private String key()
    {
        return  "app:space";
    }
}
